package cn.com.nes.site.action.iot;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.iot.ProtocolAuthService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller("ProtocolAuthAction")
@RequestMapping("/protocolAuth")
public class ProtocolAuthAction {
    @Resource
    private ProtocolAuthService protocolAuthService;

    @RequestMapping("/saveDataItemAuth")
    @ResponseBody
    public PageData saveDataItemAuth(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();

        res = protocolAuthService.saveDataItemAuth(req);
        return res;
    }

    @RequestMapping("/getDataItemAuth")
    @ResponseBody
    public PageData getDataItemAuth(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();

        res = protocolAuthService.getDataItemAuth(req);
        return res;
    }

}
